home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / despereaux-swings.swf / scripts / Box2D / Dynamics / Contacts / b2Contact.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  6.6 KB  |  227 lines

  1. package Box2D.Dynamics.Contacts
  2. {
  3.    import Box2D.Collision.*;
  4.    import Box2D.Collision.Shapes.*;
  5.    import Box2D.Common.*;
  6.    import Box2D.Common.Math.*;
  7.    import Box2D.Dynamics.*;
  8.    
  9.    public class b2Contact
  10.    {
  11.       
  12.       public static var e_toiFlag:uint = 8;
  13.       
  14.       public static var e_nonSolidFlag:uint = 1;
  15.       
  16.       public static var e_slowFlag:uint = 2;
  17.       
  18.       public static var e_islandFlag:uint = 4;
  19.       
  20.       public static var s_registers:Array;
  21.       
  22.       public static var s_initialized:Boolean = false;
  23.        
  24.       
  25.       public var m_shape1:b2Shape;
  26.       
  27.       public var m_shape2:b2Shape;
  28.       
  29.       public var m_prev:b2Contact;
  30.       
  31.       public var m_toi:Number;
  32.       
  33.       public var m_next:b2Contact;
  34.       
  35.       public var m_friction:Number;
  36.       
  37.       public var m_manifoldCount:int;
  38.       
  39.       public var m_node1:b2ContactEdge;
  40.       
  41.       public var m_node2:b2ContactEdge;
  42.       
  43.       public var m_restitution:Number;
  44.       
  45.       public var m_flags:uint;
  46.       
  47.       public function b2Contact(param1:b2Shape = null, param2:b2Shape = null)
  48.       {
  49.          m_node1 = new b2ContactEdge();
  50.          m_node2 = new b2ContactEdge();
  51.          super();
  52.          m_flags = 0;
  53.          if(!param1 || !param2)
  54.          {
  55.             m_shape1 = null;
  56.             m_shape2 = null;
  57.             return;
  58.          }
  59.          if(param1.IsSensor() || param2.IsSensor())
  60.          {
  61.             m_flags |= e_nonSolidFlag;
  62.          }
  63.          m_shape1 = param1;
  64.          m_shape2 = param2;
  65.          m_manifoldCount = 0;
  66.          m_friction = Math.sqrt(m_shape1.m_friction * m_shape2.m_friction);
  67.          m_restitution = b2Math.b2Max(m_shape1.m_restitution,m_shape2.m_restitution);
  68.          m_prev = null;
  69.          m_next = null;
  70.          m_node1.contact = null;
  71.          m_node1.prev = null;
  72.          m_node1.next = null;
  73.          m_node1.other = null;
  74.          m_node2.contact = null;
  75.          m_node2.prev = null;
  76.          m_node2.next = null;
  77.          m_node2.other = null;
  78.       }
  79.       
  80.       public static function InitializeRegisters() : void
  81.       {
  82.          var _loc1_:int = 0;
  83.          var _loc2_:int = 0;
  84.          s_registers = new Array(b2Shape.e_shapeTypeCount);
  85.          _loc1_ = 0;
  86.          while(_loc1_ < b2Shape.e_shapeTypeCount)
  87.          {
  88.             s_registers[_loc1_] = new Array(b2Shape.e_shapeTypeCount);
  89.             _loc2_ = 0;
  90.             while(_loc2_ < b2Shape.e_shapeTypeCount)
  91.             {
  92.                s_registers[_loc1_][_loc2_] = new b2ContactRegister();
  93.                _loc2_++;
  94.             }
  95.             _loc1_++;
  96.          }
  97.          AddType(b2CircleContact.Create,b2CircleContact.Destroy,b2Shape.e_circleShape,b2Shape.e_circleShape);
  98.          AddType(b2PolyAndCircleContact.Create,b2PolyAndCircleContact.Destroy,b2Shape.e_polygonShape,b2Shape.e_circleShape);
  99.          AddType(b2PolygonContact.Create,b2PolygonContact.Destroy,b2Shape.e_polygonShape,b2Shape.e_polygonShape);
  100.       }
  101.       
  102.       public static function Destroy(param1:b2Contact, param2:*) : void
  103.       {
  104.          var _loc3_:int = 0;
  105.          var _loc4_:int = 0;
  106.          var _loc5_:b2ContactRegister = null;
  107.          var _loc6_:Function = null;
  108.          if(param1.m_manifoldCount > 0)
  109.          {
  110.             param1.m_shape1.m_body.WakeUp();
  111.             param1.m_shape2.m_body.WakeUp();
  112.          }
  113.          _loc3_ = param1.m_shape1.m_type;
  114.          _loc4_ = param1.m_shape2.m_type;
  115.          (_loc6_ = (_loc5_ = s_registers[_loc3_][_loc4_]).destroyFcn)(param1,param2);
  116.       }
  117.       
  118.       public static function AddType(param1:Function, param2:Function, param3:int, param4:int) : void
  119.       {
  120.          s_registers[param3][param4].createFcn = param1;
  121.          s_registers[param3][param4].destroyFcn = param2;
  122.          s_registers[param3][param4].primary = true;
  123.          if(param3 != param4)
  124.          {
  125.             s_registers[param4][param3].createFcn = param1;
  126.             s_registers[param4][param3].destroyFcn = param2;
  127.             s_registers[param4][param3].primary = false;
  128.          }
  129.       }
  130.       
  131.       public static function Create(param1:b2Shape, param2:b2Shape, param3:*) : b2Contact
  132.       {
  133.          var _loc4_:int = 0;
  134.          var _loc5_:int = 0;
  135.          var _loc6_:b2ContactRegister = null;
  136.          var _loc7_:Function = null;
  137.          var _loc8_:b2Contact = null;
  138.          var _loc9_:int = 0;
  139.          var _loc10_:b2Manifold = null;
  140.          if(s_initialized == false)
  141.          {
  142.             InitializeRegisters();
  143.             s_initialized = true;
  144.          }
  145.          _loc4_ = param1.m_type;
  146.          _loc5_ = param2.m_type;
  147.          if((_loc7_ = (_loc6_ = s_registers[_loc4_][_loc5_]).createFcn) != null)
  148.          {
  149.             if(_loc6_.primary)
  150.             {
  151.                return _loc7_(param1,param2,param3);
  152.             }
  153.             _loc8_ = _loc7_(param2,param1,param3);
  154.             _loc9_ = 0;
  155.             while(_loc9_ < _loc8_.m_manifoldCount)
  156.             {
  157.                _loc10_ = _loc8_.GetManifolds()[_loc9_];
  158.                _loc10_.normal = _loc10_.normal.Negative();
  159.                _loc9_++;
  160.             }
  161.             return _loc8_;
  162.          }
  163.          return null;
  164.       }
  165.       
  166.       public function GetShape1() : b2Shape
  167.       {
  168.          return m_shape1;
  169.       }
  170.       
  171.       public function IsSolid() : Boolean
  172.       {
  173.          return (m_flags & e_nonSolidFlag) == 0;
  174.       }
  175.       
  176.       public function GetNext() : b2Contact
  177.       {
  178.          return m_next;
  179.       }
  180.       
  181.       public function GetManifolds() : Array
  182.       {
  183.          return null;
  184.       }
  185.       
  186.       public function GetShape2() : b2Shape
  187.       {
  188.          return m_shape2;
  189.       }
  190.       
  191.       public function GetManifoldCount() : int
  192.       {
  193.          return m_manifoldCount;
  194.       }
  195.       
  196.       public function Update(param1:b2ContactListener) : void
  197.       {
  198.          var _loc2_:int = 0;
  199.          var _loc3_:int = 0;
  200.          var _loc4_:b2Body = null;
  201.          var _loc5_:b2Body = null;
  202.          _loc2_ = m_manifoldCount;
  203.          Evaluate(param1);
  204.          _loc3_ = m_manifoldCount;
  205.          _loc4_ = m_shape1.m_body;
  206.          _loc5_ = m_shape2.m_body;
  207.          if(_loc3_ == 0 && _loc2_ > 0)
  208.          {
  209.             _loc4_.WakeUp();
  210.             _loc5_.WakeUp();
  211.          }
  212.          if(_loc4_.IsStatic() || _loc4_.IsBullet() || _loc5_.IsStatic() || _loc5_.IsBullet())
  213.          {
  214.             m_flags &= ~e_slowFlag;
  215.          }
  216.          else
  217.          {
  218.             m_flags |= e_slowFlag;
  219.          }
  220.       }
  221.       
  222.       public function Evaluate(param1:b2ContactListener) : void
  223.       {
  224.       }
  225.    }
  226. }
  227.